<template>
	<view>
		<view v-for="(item,index) in sr.tpl" :key="index"> 
			<c-parsefg-csmwj-header v-if="item.__config__.tag=='csmwj-header'" :field="item" :paper="paper" />
      
			<c-parsefg-csmwj-footer v-if="item.__config__.tag=='csmwj-footer'" :field="item" :paper="paper"/>
			<c-parsefg-csmwj-input v-if="item.__config__.tag=='csmwj-input'" ref="parseitem" :field="item" :paper="paper" :index="item.excludeheaderendIndex"/>
			<c-parsefg-csmwj-checkbox-group v-if="item.__config__.tag=='csmwj-checkbox-group'" ref="parseitem" :field="item" :paper="paper" :index="item.excludeheaderendIndex"/>
			<c-parsefg-csmwj-radio-group v-if="item.__config__.tag=='csmwj-radio-group'" ref="parseitem" :field="item" :paper="paper" :index="item.excludeheaderendIndex"/>
			<c-parsefg-csmwj-radio-group v-if="item.__config__.tag=='csmwj-score'" ref="parseitem" :field="item" :paper="paper" :index="item.excludeheaderendIndex"/>
		</view>
		
	</view>
</template>

<script>

	export default {
		name: 'c-parsefg',
		props: {
			tpl: {
				type: Array,
				default: []
			},
			paper: {
				type: Object
			},
			doing_userpaper:{
				type: Object
			},
		},
		data() {
			return {
				sr: {
					tpl: [],
				},
			};
		},
		mounted() {
			let that = this;
			that.cinit();
			console.log('sr----》', this.sr)
			//计算序号,需要跳过welcome和end的序号
			if(true){
				let excludeheaderendIndex = 0;
				for(let index in that.tpl){
					if(that.tpl[index].__config__.tag!='csmwj-header' && that.tpl[index].__config__.tag!='csmwj-footer'){
						excludeheaderendIndex++;
						that.tpl[index].excludeheaderendIndex = excludeheaderendIndex;
					}else{
						that.tpl[index].excludeheaderendIndex = 0;
					}
				}
				that.sr.tpl = that.tpl;
			}
		},
		methods: {
			cinit:function(){
				let that = this;	
			},
			// 如果校验通过则返回值,如果没有通过则返回false
			__submit:function(){
				let that = this;
				let ret = true;
				let values = [];
				for(let index in that.$refs.parseitem){
					let item = that.$refs.parseitem[index];
					let ret2 = item.__submit();
					if(ret2===false){
						ret = false;
					}
					values[index] = {id:item.field.id,__answer__:ret2};
				}
				if(ret===false){
					return false;
				}else{
					return values;
				}
			},
			__getVal:function(){
				let that = this;
				let ret = true;
				let values = [];
				for(let index in that.$refs.parseitem){
					let item = that.$refs.parseitem[index];
					let ret2 = item.__getVal();
					values[index] = {id:item.field.id,__answer__:ret2};
				}
				return values;
			}
		}
	};
</script>

<style scoped>
</style>
<!--
 * component yaoqiu:
 1. 必须由__submit方法
 2. 需要有view#errormsg,提供  _setErrorMsg和_setOkMsg方法 
 -->